//
//  AppDelegate.m
//  01 微博
//
//  Created by zhoup on 16/5/9.
//  Copyright © 2016年 zhoup. All rights reserved.
//

#import "AppDelegate.h"

#import "WPTabBarViewController.h"
#import "NewFeatureViewController.h"
#import "WPAccount.h"

@interface AppDelegate ()

@end
/*
 开发中经常进行暴力调试,但是NSLog 非常消耗性能
 在开发阶段：需要打印Log
 在发布后：需要关闭打印日志

 为什么要自定义Log?
 1.Log只需要在调试阶段(开发阶段)显示
 2.为了避免发布阶段一个一个的去注释Log
 
 目的:在调试阶段显示Log, 在发布阶段不显示Log (自动化)
 要想自定义Log必须先了解一个基本概念: 在调试阶段系统会自动给我们定义一个名字叫做DEBUG的宏, 在发布阶段会自动取消定义该宏
 */


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 1.初始化自定义Log
    // Standard lumberjack initialization
    [DDLog addLogger:[DDTTYLogger sharedInstance]];
    // And we also enable colors
    [[DDTTYLogger sharedInstance] setColorsEnabled:YES];
    DDLogDebug(@"%d %s", __LINE__ , __func__);
    DDLogInfo(@"%d %s", __LINE__ , __func__);
    DDLogWarn(@"%d %s", __LINE__ , __func__);
    
    // 2.创建Windows
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    
    
    WPAccount *account = [WPAccount accountFromSandbox];
    
    //如没有登录过，显示新特性
    if (!account) {
        NewFeatureViewController *vc = [[NewFeatureViewController alloc]init];
        self.window.rootViewController = vc;
    }
    else
    {
        
               //如果登录过，使用沙盒的数据去自动登陆
        // 3.创建设置根控制器
        WPTabBarViewController *tabBarVC = [[WPTabBarViewController alloc] init];
        self.window.rootViewController = tabBarVC;
    }
    // 3.显示Windows
    [self.window makeKeyAndVisible];
    
    // 设置导航条的外观
    [self setNavStyle];
    return YES;
}


-(void)setNavStyle
{
    // 当类第一次被加载的时调用
    // 取出导航条item的外观对象(主题对象)
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    // 设置默认状态文字的颜色
    NSMutableDictionary *md = [NSMutableDictionary dictionary];
    md[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [item setTitleTextAttributes:md forState:UIControlStateNormal];
    
    // 设置高亮状态文字的颜色
    NSMutableDictionary *higMd = [NSMutableDictionary dictionary];
    higMd[NSForegroundColorAttributeName] = [UIColor greenColor];
    [item setTitleTextAttributes:higMd forState:UIControlStateHighlighted];
    
    // 设置不可用状态的颜色
    NSMutableDictionary *disMd = [NSMutableDictionary dictionary];
    disMd[NSForegroundColorAttributeName] = [UIColor grayColor];
    [item setTitleTextAttributes:disMd forState:UIControlStateDisabled];
    
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
